var core = require('../../utils/core.js')

Page({
  data: {
      motto: 'Hello World',
      userInfo: {},
      hasUserInfo: false,
      canIUse: wx.canIUse('button.open-type.getUserInfo'),
      otheropenid:'11'
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },
  //事件处理函数
  bindViewTap: function() {
      wx.switchTab({
          url: '../home/home'
      })
  },
  getUserInfo: function() {
    var that=this
      wx.getSetting({
        success: res => {
            if (res.authSetting['scope.userInfo']) {
            // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
                wx.getUserInfo({
                    success: res => {
                       // console.log(111)
                        // 可以将 res 发送给后台解码出 unionId  
                                         
                        wx.setStorageSync('userinfo', JSON.stringify(res.userInfo))   
                        res.userInfo.otheropenid= wx.getStorageSync('otheropenid') 
                  
                        core.post("Addmember",res.userInfo,function(res){
                          if(wx.getStorageSync('otheropenid')){
                            wx.removeStorageSync('otheropenid');
                          }                        
                          var tarbarurl=wx.getStorageSync('tarbarurl');
                          if(tarbarurl){
                            wx.removeStorageSync('tarbarurl');
                            // wx.switchTab({
                            //   url:tarbarurl
                            // })
                            wx.navigateBack({
                              delta: 1
                            })
                          }else{
                            wx.navigateBack({
                              delta: 1
                            })
                          }
                          
                        })
                        
                    }
                })
            }
        }
    })

  }
})